package com.mku.wms_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mku.wms_service.common.QueryPageParam;
import com.mku.wms_service.common.Response;
import com.mku.wms_service.entity.Storage;
import com.mku.wms_service.mapper.StorageMapper;
import com.mku.wms_service.service.IStorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author maoxx
 * @since 2024-11-22
 */
@Service
public class StorageServiceImpl extends ServiceImpl<StorageMapper, Storage> implements IStorageService {

    @Override
    public Response<Page<Storage>> getListByPage(QueryPageParam qp2) {
        QueryWrapper<Storage> qw = new QueryWrapper<>();
        Page<Storage> page = new Page<>();

        page.setCurrent(qp2.getPageNum());
        page.setPages(qp2.getPageSize());

        String name = (String) qp2.getParam().get("name");

        if (name != null && !"".equals(name.trim())) {
            qw.like("name", name);
        }

        Page<Storage> pages = page(page, qw);

        return Response.success(pages);
    }

    @Override
    public Response<Storage> add(Storage storage) {
        return saveOrUpdate(storage) ? Response.success() : Response.fail("添加失败");
    }

    @Override
    public Response<Storage> delete(Integer id) {
        return removeById(id) ? Response.success() : Response.fail("删除失败");
    }

    @Override
    public Response<List<Storage>> listAll() {
        return Response.success(list());
    }
}
